<template>
  <div class="container">
    <div class="head-container item">
      <div class="title">密切接触者管理</div>
      <el-button-group class="checkout-btn-group">
        <el-button class="checkout-btn" @click="queryTableData">
          <i class="el-icon-refresh"></i>
          <span>刷新</span>
        </el-button>
      </el-button-group>
      <div class="search-container">
        <el-input class="query-input"
                  placeholder="请输入姓名"
                  v-model="key"
                  clearable>
        </el-input>
        <el-button class="search-btn" @click="queryTableData">搜索</el-button>
      </div>

    </div>
    <div class="table-container item">
      <el-table
          :header-cell-style="{'text-align':'center'}"
          :cell-style="{'text-align':'center'}"
          :data="tableData"
          border
          style="width: 100%">
        <el-table-column
            prop="base.name"
            label="姓名"
            width="120">
        </el-table-column>
        <el-table-column
            prop="base.idCard"
            label="身份证号码"
            width="200">
        </el-table-column>
        <el-table-column
            prop="base.gender"
            label="性别"
            width="80">
        </el-table-column>
        <el-table-column
            prop="comeFrom"
            label="接触源"
            width="160">
        </el-table-column>
        <el-table-column
            :show-overflow-tooltip="true"
            prop="isoAddress"
            label="隔离地址"
            width="250">
        </el-table-column>
        <el-table-column
            prop="startDate"
            width="180"
            label="隔离开始日期">
        </el-table-column>
        <el-table-column
            label="操作">
          <template slot-scope="scope">
            <el-button type="primary" size="mini" @click.native.prevent="viewMessage(scope.row)">
              详情
            </el-button>
            <el-button type="success" size="mini" @click.native.prevent="toSafe(scope.row)">
              隔离完成
            </el-button>
            <el-button type="danger" size="mini" @click.native.prevent="toPatientDialog(scope.row)">
              转为确诊
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
          class="pagination"
          background
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          layout="total, sizes,prev, pager, next,jumper"
          :page-size="pageSize"
          :page-sizes="[5,10,15]"
          :current-page.sync="pageNum"
          :total="total">
      </el-pagination>
    </div>
    <el-dialog
        title="人员信息"
        :visible.sync="messageDialogVisible">
      <div class="dialog-content">
        <div class="base-message content-container">
          <div class="dialog-base-title">基本信息</div>
          <el-table
              class="dialog-base-table"
              :header-cell-style="{'text-align':'center'}"
              :cell-style="{'text-align':'center'}"
              :data="selectRowData"
              border>
            <el-table-column
                prop="base.name"
                label="姓名"
                width="80">
            </el-table-column>
            <el-table-column
                prop="base.gender"
                label="性别"
                width="80">
            </el-table-column>
            <el-table-column
                prop="base.idCard"
                label="身份证号码">
            </el-table-column>
            <el-table-column
                :show-overflow-tooltip="true"
                prop="base.address"
                label="地址"
                width="160">
            </el-table-column>
            <el-table-column
                prop="base.phone"
                label="电话"
                width="160">
            </el-table-column>
          </el-table>
        </div>
        <div class="quarantine-message content-container">
          <div class="dialog-base-title">隔离信息</div>
          <el-table
              class="dialog-base-table"
              :header-cell-style="{'text-align':'center'}"
              :cell-style="{'text-align':'center'}"
              :data="selectRowData"
              border>
            <el-table-column
                prop="comeFrom"
                label="密切接触来源">
            </el-table-column>
            <el-table-column
                :show-overflow-tooltip="true"
                prop="isoAddress"
                label="隔离地址">
            </el-table-column>
            <el-table-column
                prop="finished"
                label="隔离是否完成">
            </el-table-column>
            <el-table-column
                prop="startDate"
                label="隔离开始时间">
            </el-table-column>
          </el-table>
        </div>
      </div>
      <span slot="footer" class="dialog-footer">
    <el-button type="primary" @click="messageDialogVisible = false">确 定</el-button>
  </span>
    </el-dialog>
    <el-dialog
        title="添加确诊病患信息"
        :visible.sync="toPatientDialogVisible">
      <div class="topatient-dialog-content">
        <el-descriptions :column="3" size="medium" border>
          <el-descriptions-item>
            <template slot="label">感染源</template>
            <el-input v-model="patient.infectionSource"></el-input>
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label">住院时间</template>
            <el-date-picker
                v-model="patient.onsetDate"
                type="date"
                placeholder="选择日期">
            </el-date-picker>
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label">症状</template>
            <el-input v-model="patient.symptoms"></el-input>
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label">诊治医院</template>
            <el-input v-model="patient.hospital"></el-input>
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label">是否重症</template>
            <el-input v-model="patient.critical"></el-input>
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label">备注</template>
            <el-input v-model="patient.note"></el-input>
          </el-descriptions-item>
        </el-descriptions>
      </div>
      <span slot="footer" class="dialog-footer">
    <el-button type="primary" @click="toPatient">确 定</el-button>
  </span>
    </el-dialog>
  </div>
</template>

<script>

import {formatDate} from "@/utils/date";
import {getTouchList, toSafe} from "@/api/touch";
import {toPatient} from "@/api/patient";

export default {
  name: "TouchManagementPage",
  data() {
    return {
      tableData: [],
      pageSize: 5,
      pageNum: 1,
      total: 1,
      key: null,
      messageDialogVisible: false,
      toPatientDialogVisible: false,
      selectRowData: [],
      patient: {
        baseId: null,
        infectionSource: null,
        onsetDate: null,
        symptoms: null,
        hospital: null,
        critical: null,
        note: null
      }
    }
  },
  methods: {
    handleCurrentChange(val) {
      this.pageNum = val;
      this.queryTableData();
    },
    handleSizeChange(val) {
      this.pageNum = 1;
      this.pageSize = val;
      this.queryTableData();
    },
    queryTableData() {
      getTouchList(this.pageNum, this.pageSize,this.key).then(res => {
        let pageInfo = res.data;
        pageInfo.list.forEach(item => {
          item.startDate = formatDate(new Date(item.startDate), "yyyy-MM-dd")

        })
        this.tableData = pageInfo.list;
        this.total = pageInfo.total;
        this.pageSize = pageInfo.pageSize;
        this.pageNum = pageInfo.pageNum;
      })
    },
    viewMessage(row) {
      this.messageDialogVisible = true;
      this.selectRowData = [];
      this.selectRowData.push(row);
    },
    toSafe(row) {
      this.$confirm(row.base.name + '将要完成隔离, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        toSafe(row.baseId).then(res => {
          this.queryTableData();
          this.$message({
            type: 'success',
            message: '操作成功!'
          });
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消操作'
        });
      });
    },
    toPatientDialog(row) {
      this.toPatientDialogVisible = true;
      this.selectRowData = [];
      this.selectRowData.push(row);
    },
    toPatient() {

      this.$confirm(this.selectRowData[0].base.name + '将要转为确诊, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.patient.baseId = this.selectRowData[0].baseId;
        toPatient(this.patient).then(res => {
          this.queryTableData();
          this.$message({
            type: 'success',
            message: '操作成功!'
          });
          this.toPatientDialogVisible = false;
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消操作'
        });
      });
    },
  },
  mounted() {
    this.queryTableData();
  }
}
</script>

<style scoped>
.container {
  border-top: 3px solid #3c8dbc;
  border-radius: 3px;
  background-color: white;
  margin-left: 20px;
  margin-right: 20px;
}

.item {
  margin-right: 10px;
  margin-left: 10px;
}

.table-container {
  text-align: center;
}

.checkout-btn-group {

}

.checkout-btn {
  margin-top: 10px;
  margin-bottom: 10px;
}

.title {
  font-size: 20px;
  padding-top: 10px;
}

.pagination {
  padding-top: 20px;
  padding-bottom: 20px;
}

.search-container {
  display: inline-block;
  float: right;
}

.query-input {
  display: inline-block;
  margin-right: 10px;
  width: 180px;
}

.dialog-base-title {
  font-size: 15px;
  padding: 5px;
}

.dialog-base-table {
  width: 100%;
}

.content-container {
  margin-top: 20px;
  background-color: #E9EEF3;
}

</style>
